package com.yanlin.serviceDriverUser.service.impl;

import com.yanlin.internalcommon.dto.Car;
import com.yanlin.internalcommon.dto.ResponseResult;
import com.yanlin.serviceDriverUser.mapper.CarMapper;
import com.yanlin.serviceDriverUser.service.ICarService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yanlin
 * @since 2025-06-13
 */
@Service
public class CarServiceImpl extends ServiceImpl<CarMapper, Car> implements ICarService {

    @Autowired
    private CarMapper carMapper;

    @Override
    public ResponseResult getCar(Integer state) {
        Map<String, Object> map = new HashMap<>();
        map.put("state", state);
        List<Car> cars = carMapper.selectByMap(map);
        if (cars.size() < 1) {
            return ResponseResult.fail("");
        }
        Car car = cars.get(0);
        return ResponseResult.success(car);
    }

    @Override
    public ResponseResult addCar(Car car) {
        car.setGmtModified(LocalDateTime.now());
        car.setGmtCreate(LocalDateTime.now());
        carMapper.insert(car);
        return ResponseResult.success();
    }


}
